﻿using stdCall.Models;
using stdCall.MyRandom;
using stdCall.Resource;
using stdCall;
using System.Windows.Forms;

namespace stdCall.MyAnimate
{
    /// <summary>
    /// 继承ResourceGet，提供动画包的服务
    /// </summary>
    class AnimateService:ResourceGet
    {
        public static int animateNum=10;
        private static bool flagEvenCurrent = false;
        private static bool flagEvenNext = false;
        private static bool resouceFlag_current = false;
        private static bool resouceFlag_next = false;
        private Animate animate = new Animate();
        private static Label label_hideNextStd;
        private static Label label_hideCurrentStd;
        private static Label label_nextStd;
        private static Label label_currentStd;
        private static Panel panel_current;
        private static Panel panel_nextstd;
        /// <summary>
        /// 下一个学生标签的动画切换，并更换Random.nextStudent
        /// </summary>
        public Student animateNextAndReturnStd()
        {
            if (!resouceFlag_next)
            {
                 label_hideNextStd = (Label)resources["label_hideNextStd"];
                 label_nextStd = (Label)resources["label_nextStd"];
                 panel_nextstd = (Panel)resources["panel_nextstd"];
                resouceFlag_next = true;
            }
            Student std = null;
            for (int i = 0; i < animateNum; i++)
            {
                std = Caculator.getAPoorStdNum(new StudentsManager().getAllStudents());
                if (!flagEvenNext)
                {
                    label_hideNextStd.Text = std.Name;
                    animate.switchLabel(label_nextStd,
                        label_hideNextStd,
                            panel_nextstd,
                    i);
                    flagEvenNext = true;
                }
                else
                {
                    label_nextStd.Text = std.Name;
                    animate.switchLabel(label_hideNextStd,
                        label_nextStd,
                    panel_nextstd, 
                    i);
                    flagEvenNext = false;
                }
            }
            return std;
        }

        /// <summary>
        /// 当前学术标签的动画切换，需传参，因为分两种逻辑：开始和评价的逻辑有区别
        /// Random.currentstd未更改
        /// </summary>
        /// <param name="stdShow">当前学生</param>
        /// <param name="speed">速度</param>
        public void animateCurrentStd(Student stdShow, int speed)
        {
            if (!resouceFlag_current)
            {
                label_hideCurrentStd = (Label)resources["label_hideCurrentStd"];
                label_currentStd = (Label)resources["label_currentStd"];
                panel_current = (Panel)resources["panel_current"];
                resouceFlag_current = true;
            }
           // RandomService.currentStudent = stdShow;
            if (!flagEvenCurrent)
            {
                label_hideCurrentStd.Text = stdShow.Name;
                animate.switchLabel(
                    label_currentStd,
                     label_hideCurrentStd,
                     panel_current,
                    speed);
                flagEvenCurrent = true;
            }
            else
            {
                label_currentStd.Text = stdShow.Name;
                animate.switchLabel(label_hideCurrentStd,
                label_currentStd,
                panel_current,
                speed);
                flagEvenCurrent = false;
            }
        }

    }
}
